var SearchRequest = new Class({
  initialize: function(search_request){
    search_request.addEvent('click', function(event){
      event.stop();
      var gallery_id  = $('gallery_id').get('value');
      var term        = $('term').get('value');
      var req         = new Request.HTML({method:'get', url:'/search/gallery_photo_search?term='+term+'&gallery_id='+gallery_id,
        onSuccess: function(html) {
          $('photos').empty();
          $('photos').adopt(html);
        },
        onFailure: function() {
          $('photos').set('text', 'Something went wrong.');
        }
      });
      req.send();
    })
  },
});

window.addEvent('domready', function() {
  $$('.search').each(function(search_item){
    new SearchRequest(search_item);
  });
});